package com.example.administrator.swredeem.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.swredeem.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TobuygasActivity extends AppCompatActivity implements View.OnFocusChangeListener {

    @BindView(R.id.money)
    EditText money;
    @BindView(R.id.quantity)
    EditText quantity;

    private boolean isMoney = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tobuygas);
        ButterKnife.bind(this);
        init();


    }

    private void init() {
        money.setOnFocusChangeListener(this);
        quantity.setOnFocusChangeListener(this);
    }


    public void goShowrecharge(View view) {
        if (!TextUtils.isEmpty(money.getText().toString().trim())) {
            goNext();
        } else if (!TextUtils.isEmpty(quantity.getText().toString().trim())) {
            goNext();
        } else {
            Toast.makeText(TobuygasActivity.this, "请输入购气量", Toast.LENGTH_SHORT).show();
        }
    }

    public void goNext() {
        Intent intent = getIntent();
        String title = intent.getStringExtra("title");
        String userid = intent.getStringExtra("userid");
        String factory = intent.getStringExtra("factory");
        Intent intent1 = new Intent(TobuygasActivity.this, ShowRechargeActivity.class);
        intent1.putExtra("title", title);
        intent1.putExtra("userid", userid);
        intent1.putExtra("money", money.getText().toString().trim());
        intent1.putExtra("quantity", quantity.getText().toString().trim());
        intent1.putExtra("factory", factory);
        startActivity(intent1);
    }

    //获取监听
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        switch (v.getId()) {
            case R.id.money:
                if (hasFocus) {
                    isMoney = true;
                    quantity.setText("");
                }
                break;

            case R.id.quantity:
                if (hasFocus) {
                    isMoney = false;
                    money.setText("");
                }
                break;
        }
    }
}
